package com.corpgovernment.common.apollo;

import com.google.common.collect.Sets;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.HashSet;

/**
 * @ClassName: HotelApollo
 * @description: 酒店阿波罗配置
 * @author: ezchen
 * @date: Created in 15:59 2020/7/9
 * @Version: 1.0
 **/
@Data
@Component
public class HotelApollo extends CommonApollo {

    /**
     * 酒店匹配度
     */
    @Value("${mapping.matchPercent:0.8}")
    private Double matchPercent;
    /**
     * 最大距离
     */
    @Value("${mapping.maxDistance:5000}")
    private Integer maxDistance;
    /**
     * 酒店图片路径
     */
    @Value("${ctrip.file.prefix:http://images4.fx.ctripcorp.com/target/}")
    private String ctripHotelPicUrlPrefix;
    /**
     * 停留时间校验 时间/秒
     */
    @Value("${bookTimeout:1200}")
    private Long bookTimeout;
    /**
     * 超时未确认 时间/分钟
     */
    @Value("${timeoutNotConfirm:30}")
    private Integer timeoutNotConfirm;
    /**
     * 模糊搜索的服务商code
     */
    @Value("${searchLocation.supplierCode:}")
    private String searchLocationSupplierCode;
    /**
     * 模糊搜索的服务商corpId
     */
    @Value("${searchLocation.supplierCorpId:}")
    private String searchLocationSupplierCorpId;
    /**
     * 酒店查询接口超时时间，单位：秒
     */
    @Value("${supplierTimeOut:20}")
    private Long supplierTimeOut;
    /**
     * 酒店列表缓存时间，单位：秒
     */
    @Value("${HotelListCacheTime:600}")
    private Long hotelListCacheTime;

    @Value("${hotelMappingUrl:}")
    private String hotelMappingUrl;

    @Value("${search.hotel.request.scenicId.mapping.cityId:}")
    private String searchHotelRequestScenicIdMappingCityId;

    @Value("${hotelCompare:}")
    private String hotelCompare;

    @Value("${hotelSearchSupplierFilter:''}")
    private String hotelSearchSupplierFilter;

    /**
     * 使用新列表查询逻辑的组织id
     */
    @Value("${enableNewHotelListOrgId:''}")
    private String enableNewHotelListOrgId;

    public String getHotelSearchSupplierFilter() {
        return getAppProperty("hotelSearchSupplierFilter", "");
    }

    public String getHotelCompare() {
        return getAppProperty("hotelCompare", "");
    }

    public String getHotelMappingUrl() {
        return getAppProperty("hotelMappingUrl", "");
    }

    public Double getMatchPercent() {
        return Double.parseDouble(getAppProperty("mapping.matchPercent", "0.8"));
    }

    public Integer getMaxDistance() {
        return Integer.parseInt(getAppProperty("mapping.maxDistance", "5000"));
    }

    public String getCtripHotelPicUrlPrefix() {
        return getAppProperty("ctrip.file.prefix", "http://images4.fx.ctripcorp.com/target/");
    }

    public Long getBookTimeout() {
        return Long.parseLong(getAppProperty("bookTimeout", "1200"));
    }

    public String getSearchLocationSupplierCode() {
        return getAppProperty("searchLocation.supplierCode", "");
    }

    public String getSearchLocationSupplierCorpId() {
        return getAppProperty("searchLocation.supplierCorpId", "");
    }

    public Long getSupplierTimeOut() {
        return Long.parseLong(getAppProperty("supplierTimeOut", "20"));
    }

    public Long getHotelListCacheTime() {
        return Long.parseLong(getAppProperty("HotelListCacheTime", "1800"));
    }

    public Integer getTimeoutNotConfirm() {
        return Integer.parseInt(getAppProperty("timeoutNotConfirm", "30"));
    }

    /**
     * 是否使用新列表查询逻辑
     */
    public boolean enableNewHotelList(String orgId) {
        HashSet<String> enableNewHotelListOrgIdSet = Sets.newHashSet(getAppProperty("enableNewHotelListOrgId", "").split("\\|"));
        if (enableNewHotelListOrgIdSet.size() == 1 && enableNewHotelListOrgIdSet.stream().allMatch("ALL"::equals)) {
            return true;
        }
        return enableNewHotelListOrgIdSet.contains(orgId);
    }
}
